#!/bin/sh

PROTEIN=$1

RNA=$2

GENOMESIZE=`head -1 $PROTEIN | perl -nle 'if($_ =~ /.*\.\.(\d+)/) {print $1}'`

ORGANISM=`head -1 $PROTEIN | awk '{print $1, $2, $3}'`

TOTALPROTEIN=`perl -nle 'if($_ =~ /^(\d+)\.\.(\d+).*/) {print $2-$1+1}' $PROTEIN | awk '{sum += $1}END{print sum}'`

#TOTALPROTEIN=`grep $LOCUSNAME $PROTEIN | perl -nle '@data = split(/\t/, $_); @coords = split(/\.\./, $data[0]); print $coords[1]-$coords[0]+1' | awk '{sum += $1}END{print sum}'`

#TOTALRNA=`grep $LOCUSNAME $RNA | perl -nle '@data = split(/\t/, $_); @coords = split(/\.\./, $data[0]); print $coords[1]-$coords[0]+1' | awk '{sum += $1}END{print sum}'`
TOTALRNA=`perl -nle 'if($_ =~ /^(\d+)\.\.(\d+).*/) {print $2-$1+1}' $RNA | awk '{sum += $1}END{print sum}'`

TOTALCOUNT=$((TOTALPROTEIN + TOTALRNA))

echo "organism " $ORGANISM

echo "genome_size " $GENOMESIZE

echo "total_coding " $TOTALCOUNT

echo 1 | awk '{print "percent_coding ", ('$TOTALCOUNT'/'$GENOMESIZE')*100}'
